package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.service.FileUploadService;
import io.minio.MinioClient;
import io.minio.errors.InvalidEndpointException;
import io.minio.errors.InvalidPortException;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * SPH_Demo01
 * 2022/11/3 12 51
 */
@RestController
@RequestMapping("/admin/product")
public class FileUploadController {
    @Autowired
    FileUploadService fileUploadService;

    @PostMapping("/fileUpload")
    public Result fileUpload(@RequestPart("file") MultipartFile multipartFile)  {
        String url = null;
        try {
            url = fileUploadService.fileUpload(multipartFile);
        } catch (Exception e) {
            throw new RuntimeException (e);
        }

        return Result.ok (url);
    }
}
